import { getSessionTabsValue } from "@/common/utils/storage"
const initTabsValue = getSessionTabsValue() || [{
    title: "首页",
    path: '/home',
    name: 'Home'
}]
export default {
    state: () => ({
        tabsValue: initTabsValue,
    }),
    getters: {},
    mutations: {
        /**
         * 删除标签页
         * @param {*} state 
         * @param {*} targetPath 
         */
        REMOVE_TABS_VALUE(state, targetPath) {
            state.tabsValue = state.tabsValue.filter(tab => tab.path !== targetPath)
        },
        /**
         * 添加标签页
         * @param {*} state 
         * @param {*} data 
         */
        ADD_TABS_VALUE(state, data) {
            // 判断是否存在
            const isExist = state.tabsValue.some((tab) => tab.path === data.path)
            if (!isExist) {
                state.tabsValue.push(data)
            }
        },
        /**
         * 用户注销后清楚tabsvalue
         * @param {*} state 
         */
        RESET_TABS_VALUE(state) {
            state.tabsValue = [{
                title: "首页",
                path: "/home",
                name: "Home"
            }]
        }
    },
    actions: {}
}